package com.slg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.slg.entity.JsonResponse;
import com.slg.entity.dto.EmployeeDto;
import com.slg.entity.dto.SalaryDto;
import com.slg.entity.pojo.Employee;
import com.slg.entity.pojo.Page;
import com.slg.entity.pojo.Salary;
import com.slg.entity.pojo.Shenqing;
import com.slg.mapper.AdminiMapper;
import com.slg.service.AdminiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdiminiServiceImpl implements AdminiService {
    @Resource
    AdminiMapper adminiMapper;

    @Override
    public int updateEmployee(Employee employee) {
        return adminiMapper.updateEmployee(employee);
    }

    @Override
    public int updateSalary1(SalaryDto salaryDto) {
        return adminiMapper.updateSalary1(salaryDto);
    }

    @Override
    public int deleteEmployee(int id) {
        return adminiMapper.deleteEmployee(id);
    }

    @Override
    public int deleteEmployee1(int id) {
        return adminiMapper.deleteEmployee1(id);
    }

    @Override
    public int add(Employee employee) {
        return adminiMapper.add(employee);
    }

    @Transactional
    @Override
    public int add1(SalaryDto salaryDto) {
        int i = adminiMapper.add1(salaryDto);
        int x =  adminiMapper.add2(salaryDto);
        return x;
    }

    @Override
    public Page<Shenqing> queryDatabase1(Integer pageNum,Integer pageSize) {
        //        分页查询,起始页和每页查询数量
        PageHelper.startPage(pageNum,pageSize);
//        查询影视数据列表
        List<Shenqing> shenqingList= adminiMapper.queryDatabase1();
//        使用PageInfo帮助我们计算所有的分页数据
        PageInfo<Shenqing> pageInfo=new PageInfo<>(shenqingList);

        return new Page<>(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getList(),pageInfo.getPages(),pageInfo.getTotal(),
                pageInfo.getPrePage(),pageInfo.getNextPage());

    }

    @Override
    public int jujube(int id) {
        return adminiMapper.jujube(id);
    }

    @Override
    public int updateSalary3(int id) {
        return adminiMapper.updateSalary3(id);
    }

    //    第一行的分页查询
    //1.1用户管理操作
    public Page<Employee> queryEmployee(Integer pageNum, Integer pageSize, Employee employee){
        //        分页查询,起始页和每页查询数量
        PageHelper.startPage(pageNum,pageSize);
//        查询影视数据列表
        List<Employee> employees= adminiMapper.queryEmployee(employee);
//        使用PageInfo帮助我们计算所有的分页数据
        PageInfo<Employee> pageInfo=new PageInfo<>(employees);

        return new Page<>(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getList(),pageInfo.getPages(),pageInfo.getTotal(),
                pageInfo.getPrePage(),pageInfo.getNextPage());
    }
//第二行的分页查询
//1.2工资类型管理
    @Override
    public Page<Salary> querySalary(Integer pageNum, Integer pageSize, Salary salary) {
        PageHelper.startPage(pageNum,pageSize);
        List<Salary> salaries = adminiMapper.querySalary(salary);
        PageInfo<Salary>salaryPageInfo = new PageInfo<>(salaries);
        return new Page<>(salaryPageInfo.getPageNum(),salaryPageInfo.getPageSize(),
                salaryPageInfo.getList(),salaryPageInfo.getPages(),salaryPageInfo.getTotal(),
                salaryPageInfo.getPrePage(),salaryPageInfo.getNextPage());
    }
//登录功能
    @Override
    public Employee login(Employee employee) {
        return  adminiMapper.login(employee);

    }



//2.2工资信息管理
    @Override
    public Page<SalaryDto> querySalaryDto(Integer pageNum, Integer pageSize, Salary salary) {
        //        分页查询,起始页和每页查询数量
        PageHelper.startPage(pageNum,pageSize);
//        查询影视数据列表
        List<SalaryDto> salaryDtos= adminiMapper.querySalaryDto(salary);
//        使用PageInfo帮助我们计算所有的分页数据
        PageInfo<SalaryDto> pageInfo=new PageInfo<>(salaryDtos);

        return new Page<>(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getList(),pageInfo.getPages(),pageInfo.getTotal(),
                pageInfo.getPrePage(),pageInfo.getNextPage());
    }
    //3.1查询本人信息
    @Override
    public Salary querySalaryByOne(Integer id) {
        return adminiMapper.querySalaryByOne(id);
    }

    @Override
    public List<Salary> queryDatabase() {
        return adminiMapper.queryDatabase();

    }

    @Override
    public int updateException( Shenqing salaryDto) {
        return adminiMapper.updateException(salaryDto);
    }
//3.3异常数据申诉信息
//    @Override
//    public int updateException(String position, Integer basicsalary, Integer jiangjin, Integer baoxiao, Integer id) {
//       return adminiMapper.updateException( position,  basicsalary,  jiangjin,  baoxiao,  id);
//
//    }

    @Override
    public int setBaoXiao(Integer baoxiao,Integer id) {
        return adminiMapper.setBaoXiao(baoxiao,id);
    }

    //员工查自己的薪资


    @Override
    public Employee getUserByUserName(String userName) {
        return adminiMapper.getUserByUserName(userName);
    }
}
